// https://leetcode.cn/problems/group-anagrams/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> strMap;

        for (string str : strs) {
            string tmp = str;
            sort(tmp.begin(), tmp.end());
            strMap[tmp].emplace_back(str);
        }

        vector<vector<string>> ans;
        for (auto it = strMap.begin(); it != strMap.end(); it++) {
            ans.emplace_back(it->second);
        }
        return ans;
    }
};